<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="java.util.Map"%>
<%@page import="it.unibz.ti2.internetPizzeria.entities.Pizza"%>

<html>
<head>
	<title>Internet pizzeria - New order</title>
<%	
		Map<Pizza, Integer> pizzasMap = (Map<Pizza, Integer>)(request.getAttribute("pizzasMap"));
		Map<Drink, Integer> drinksMap = (Map<Drink, Integer>)(request.getAttribute("drinksMap"));	
%>
	<script type="text/javascript">
		function load(){
<%			for (Map.Entry<Pizza, Integer> entry : pizzasMap.entrySet()) {
%>
				var price = <%out.print(entry.getKey().getPrice());%>;
				var price2 = <%out.print(entry.getKey().getPrice()*entry.getValue().intValue());%>;

				document.getElementById("tablePizzaTdI<%out.print(entry.getKey().getId());%>").innerHTML = price.toFixed(2);
				document.getElementById("tablePizzaTdII<%out.print(entry.getKey().getId());%>").innerHTML = price2.toFixed(2);
<%			}
			for (Map.Entry<Drink, Integer> entry : drinksMap.entrySet()) {
%>
				var price = <%out.print(entry.getKey().getPrice());%>;
				var price2 = <%out.print(entry.getKey().getPrice()*entry.getValue().intValue());%>;
				
				document.getElementById("tableDrinkTdI<%out.print(entry.getKey().getId());%>").innerHTML = price.toFixed(2);
				document.getElementById("tableDrinkTdII<%out.print(entry.getKey().getId());%>").innerHTML = price2.toFixed(2);
<%			}
%>
				var price1 = <%out.print(request.getAttribute("price").toString());%>;
				var price2 = <%out.print(request.getAttribute("feeForDelivery").toString());%>;
				var price3 = <%out.print( (Float)(request.getAttribute("price"))+(Float)(request.getAttribute("feeForDelivery")) );%>;
			
				document.getElementById("tableSumTd").innerHTML = 
					"Price: <b>"+price1.toFixed(2)+"</b><br /> Delivery fee: <b>"+price2.toFixed(2)+"</b><br /><hr />Sum: <b>"+price3.toFixed(2)+"</b><br />";
		}
	</script>
</head>
<body onload="load()">	
<%@ include file="navigationMenu.jsp" %>
	<h3>Order confirmation</h3>
	<form method="post" action="newOrderConfirmation2">
	<input type="hidden" name="pointLat" value="<%out.print(request.getAttribute("pointLat"));%>" />
	<input type="hidden" name="pointLng" value="<%out.print(request.getAttribute("pointLng"));%>" />
	
	<table>
		<tr>
			<th colspan="6" bgcolor="EEEEEE">Choosen products</th>
		</tr>
		<tr>
			<th width="100" bgcolor="EEEEEE">Product number</td>
			<th width="100" bgcolor="DDDDDD">Product name</td>
			<th width="200" bgcolor="EEEEEE">Product description</td>
			<th width="100" bgcolor="DDDDDD">Product price</td>
			<th width="100" bgcolor="EEEEEE">Amount of product</td>
			<th width="130" bgcolor="DDDDDD">Price</td>
		</tr>
	<%
		for (Map.Entry<Pizza, Integer> entry : pizzasMap.entrySet()) {
			//if (entry.getValue().intValue()>0){	
	%>
		<tr>
			<td align="center" bgcolor="EEEEEE"><%out.print(entry.getKey().getId());%></td>
			<td bgcolor="DDDDDD"><%out.print(entry.getKey().getName());%></td>
			<td bgcolor="EEEEEE"><%out.print(entry.getKey().getDescription());%></td>
			<td id="tablePizzaTdI<%out.print(entry.getKey().getId());%>" align="right" bgcolor="DDDDDD"></td>
			<td align="right" bgcolor="EEEEEE"><%out.print(entry.getValue().intValue());%></td>
			<td id="tablePizzaTdII<%out.print(entry.getKey().getId());%>" align="right" bgcolor="DDDDDD"></td>
			<input type="hidden" name="pizzasIds" value="<%out.print(entry.getKey().getId());%>" />
			<input type="hidden" name="numberOfPizzas<%out.print(entry.getKey().getId());%>" value="<%out.print(entry.getValue().intValue());%>" />
		</tr>
	<%	}
		for (Map.Entry<Drink, Integer> entry : drinksMap.entrySet()) {
			//if (entry.getValue().intValue()>0){	
	%>
		<tr>
			<td align="center" bgcolor="EEEEEE"><%out.print(entry.getKey().getId());%></td>
			<td bgcolor="DDDDDD"><%out.print(entry.getKey().getName());%></td>
			<td bgcolor="EEEEEE"><%out.print(entry.getKey().getDescription());%></td>
			<td id="tableDrinkTdI<%out.print(entry.getKey().getId());%>" align="right" bgcolor="DDDDDD"></td>
			<td align="right" bgcolor="EEEEEE"><%out.print(entry.getValue().intValue());%></td>
			<td id="tableDrinkTdII<%out.print(entry.getKey().getId());%>" align="right" bgcolor="DDDDDD"></td>
			<input type="hidden" name="drinksIds" value="<%out.print(entry.getKey().getId());%>" />
			<input type="hidden" name="numberOfDrinks<%out.print(entry.getKey().getId());%>" value="<%out.print(entry.getValue().intValue());%>" />
		</tr>
	<%	}
	%>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td id="tableSumTd" align="right" bgcolor="DDDDDD">
			</td>
			<input type="hidden" name="productsPrice" value=<%out.print(request.getAttribute("price"));%> />
			<input type="hidden" name="deliveryPrice" value=<%out.print(request.getAttribute("feeForDelivery"));%> />
			<input type="hidden" name="sumPrice" value=<%out.print( (Float)(request.getAttribute("price"))+(Float)(request.getAttribute("feeForDelivery")) );%> />
		</tr>
	</table>
	<h4>Address where you want to receive the package</h4>
	<table>
		<tr>
			<td> name: </td>
			<td><%out.print(request.getAttribute("name"));%>
			<input type="hidden" name="userName" value="<%out.print(request.getAttribute("name"));%>" /><br/></td>
		</tr>
		<tr>
			<td>surname: </td>
			<td><%out.print(request.getAttribute("surname"));%>
			<input type="hidden" name="userSurname" value="<%out.print(request.getAttribute("surname"));%>" /></td>
		</tr>
		<tr>
			<td>city: </td>
			<td><%out.print(request.getAttribute("city"));%>
			<input type="hidden" name="userCity" value="<%out.print(request.getAttribute("city"));%>" /></td>
		</tr>
		<tr>
			<td>street and number: </td> 
			<td><%out.print(request.getAttribute("streetAndNumber"));%>
			<input type="hidden" name="userStreetAndNumber" value="<%out.print(request.getAttribute("streetAndNumber"));%>" /></td>
		</tr>
		<tr>
			<td>country: </td> 
			<td><%out.print(request.getAttribute("country"));%>
			<input type="hidden" name="userCountry" value="<%out.print(request.getAttribute("country"));%>" /></td>
		</tr>
		<tr>	
			<td>zip code: </td> 
			<td><%out.print(request.getAttribute("zipCode"));%>
			<input type="hidden" name="userZipCode" value="<%out.print(request.getAttribute("zipCode"));%>" /></td>
		</tr>
	</table>
	
	<input type="submit" name="orderconfirmation_submit" value="Confirm">
	</form>
	
	
	
</body>
</html>
